<?php

namespace IDock\Insurance\ZYIC\Response;

use IDock\Http\Response;
use IDock\Insurance\ZYIC\Response\AllZYICResponse;
use IDock\Printer\PremiumUnderwritingPrinter;

class UnderwritingResponse extends AllZYICResponse
{

    /**
     * @var PremiumUnderwritingPrinter $printer
     */
    public $printer = PremiumUnderwritingPrinter::class;

    public function printerInit(): Response
    {
        $data = $this->getBody()['content'][0] ?? [];

        $code = $data['underwriteFlag'] ?? '';

        $this->printer->inquiryNo = '';
        $this->printer->ciInquiryNo = $data['businessNoCI'] ?? '';
        $this->printer->biInquiryNo = $data['businessNo'] ?? '';
        $this->printer->messageTip = $data['undwrtInfo'] ?? '';

        //下发
        if ($code == '2') {
            $this->printer->statusCode = 'U4';
        }
        //成功
        if (in_array($code,['1','4','5']))  {
            $this->printer->statusCode = 'U1';
            $this->printer->argc['underwritingPass'] = true;
        }
        //人工
        if ($code == '9') {
            $this->printer->statusCode = 'U3';
            $this->printer->argc['underwritingPass'] = true;
        }
        return $this;
    }
}
